<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <el-row>
          <el-col :span="12">
            <el-breadcrumb :separator-icon="ArrowRight">
              <el-breadcrumb-item :to="{ path: '/apps' }">应用列表</el-breadcrumb-item>
              <el-breadcrumb-item>应用管理</el-breadcrumb-item>
            </el-breadcrumb>
          </el-col>
          <el-col :span="12" style="text-align: right">
            <el-button type="primary" :icon="Edit" @click="toApp">应用信息</el-button>
            <el-button type="primary" :icon="Document" @click="toInfo">资料管理</el-button>
            <el-button type="primary" :icon="DocumentAdd" @click="toPublish">应用发布</el-button>
            <el-button type="primary" :icon="Check" @click="toCheck">审核详情</el-button>
          </el-col>
        </el-row>
      </el-header>
      <el-main>
        <!-- 表格 -->
        <VersionList ref="versionVue" />
      </el-main>
    </el-container>
    <el-dialog v-model="appVisiable" title="应用信息" width="60%" destroy-on-close>
      <AppEdit />
    </el-dialog>
    <el-dialog v-model="infoVisible" title="应用资料管理" width="60%" destroy-on-close>
      <AppInfo />
    </el-dialog>
    <el-dialog v-model="publishVisible" title="应用发布" destroy-on-close>
      <AppPublish />
    </el-dialog>
    <el-dialog v-model="checkVisible" title="应用审核详情" destroy-on-close>
      <AppCheck />
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { ref, provide } from 'vue'
import {
  Plus,
  Edit,
  Check,
  ArrowRight,
  DocumentAdd,
  Document,
  Refresh
} from '@element-plus/icons-vue'
import AppInfo from '@/views/app-info.vue'
import AppCheck from '@/views/app-check.vue'
import AppPublish from '@/views/app-publish.vue'
import VersionAdd from '@/views/version-add.vue'
import VersionList from '@/views/version-list.vue'
import AppEdit from '@/views/app-edit.vue'

// 控制资料管理页面
const infoVisible = ref(false)
// 打开资料页面
const toInfo = () => {
  infoVisible.value = true
}
// 关闭资料页面
const closeInfo = () => {
  infoVisible.value = false
}

// 控制应用发布页面
const publishVisible = ref(false)
const toPublish = () => {
  publishVisible.value = true
}
const closePublish = () => {
  publishVisible.value = false
}

// 是否显示审核页面
const checkVisible = ref(false)
// 打开审核详情
const toCheck = () => {
  checkVisible.value = true
}
// 打开审核详情
const closeCheck = () => {
  checkVisible.value = false
}

const appVisiable = ref(false)
const toApp = () => {
  appVisiable.value = true
}
const closeApp = () => {
  appVisiable.value = false
}

const versionVue = ref()
const refresh = () => {
  versionVue.value.refresh()
}

provide('closeInfo', closeInfo)
provide('closePublish', closePublish)
provide('closeCheck', closeCheck)
provide('closeApp', closeApp)
provide('refreshVersions', refresh)
</script>

<style>
.el-table .warning-row {
  --el-table-tr-bg-color: var(--el-color-warning-light-9);
}
.el-table .success-row {
  --el-table-tr-bg-color: var(--el-color-success-light-9);
}
</style>
